package jude.java.money.chong;

import java.io.IOException;
import java.io.Writer;

import org.apache.commons.lang.StringUtils;

public class SiteKeywords {

	private String[] sites;
	private String[][] keywords;
	
	public SiteKeywords(String site, String[] keywords) {
		this(new String[] {site}, new String[][] {keywords});
	}
	
	public SiteKeywords(String[] sites, String[] keywords) {
		this(sites, new String[][] {keywords});
	}
	
//	public SiteKeywords(String[] keywords, String... sites) {
//		this(sites, new String[][] {keywords});
//	}
	
	public SiteKeywords(String site, String[]... keywords) {
		this(new String[] {site}, keywords);
	}
	
	public SiteKeywords(String[] sites, String[][] keywords) {
		this.sites = sites;
		this.keywords = keywords;
	}
	
	public void build(Writer writer) throws IOException {
		StringBuilder sb = new StringBuilder(100);
		for (int i = 0; i < sites.length; i++) {
			String site = sites[i];
			if (StringUtils.isEmpty(site))
				continue;
			for (int j = 0; j < keywords.length; j++) {
				String[] keys = keywords[j];
				for (int k = 0; k < keys.length; k++) {
					sb.setLength(0);
					sb.append(keys[k]).append(",");
					sb.append("http://www.").append(site);
					sb.append(",1").append("\r\n");
					writer.write(sb.toString());
				}
			}
		}
	}
}
